home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue25 / compress / COMPRESS.ZIP / SELFEXTF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-07-09  |  4.3 KB  |  122 lines

  1. unit Selfextf;
  2. (*
  3.   Self-Extracting-EXE example program for TCompress 3.0 -- no change from V2.5
  4.   This provides instructions and working code examples for:
  5.     a) Creating a compressed archive as a resource
  6.     b) Loading the compressed resource using LoadCompressedResource
  7.     c) Expanding the compressed archive into a directory with ExpandFilesFromStream
  8.  
  9.   Notes:
  10.   a) For an example which compresses and loads individual bitmaps, see BMTEST.DPR
  11.   b) For an example with NO forms overhead (but hence no user interface), see SELFXSML.DPR
  12.   c) This code has been tested satisfactorily with Delphi 2.0/3.0 and C++ Builder. With
  13.      Delphi 1.02 we encountered exceptions on ONE of our test systems
  14.      (Windows95 with Service Pack 1 and SP1 patches installed) which we have not
  15.      been able to eliminate after substantial tracing and testing.
  16.      Your mileage may vary.
  17.  
  18.   INSTRUCTIONS
  19.   ============
  20.   Part A: Creating a compressed archive as a resource:
  21.   1. Use COMPDEMO to make a new compressed archive (e.g. MYARCHIV.ARC) containing
  22.      all the files you want to automatically install (try NOTEPAD.EXE and a
  23.      simple README.TXT for example)
  24.   2. Create a text file called COMP_RES.RC containing the following (where
  25.      any reference to MYARCHIV is replaced with the correct name of your archive):
  26. /* Compile this file with (16-bit): bin\brc -r COMP_RES.RC
  27.    or                     (32-bit): bin\brc32 -r COMP_RES.RC
  28.    That will create a COMP_RES.RES file which should be included in the main
  29.    unit of your project.
  30. */
  31. MyArchiv TCOMPRESS "MyArchiv.arc"
  32.    (you can have additional lines for other resources if necessary)
  33.  
  34.   3. Compile the resource file per the instructions in its header.
  35.      Note the {$R COMP_RES.RES} reference to it in this file (just after
  36.      the start of the 'implementation' section.
  37.   4. Alter the PROG_NAME and README_NAME constants below to
  38.      refer to the correct files (they're optional, so blank is ok)
  39.  
  40.   Part B: Loading the compressed resource using LoadCompressedResource
  41.   5. Refer to the code in DOINSTAL.PAS -- it is called when the INSTALL button
  42.   on this form is pushed. Change the RESOURCE_NAME constant to be the correct
  43.   name of your resource (e.g. MyArchiv).
  44.   6. The resource loading (in compressed form) is accomplished with the line:
  45.         TempStream := LoadCompressedResource(RESOURCE_NAME,'');
  46.  
  47.   Part C: Expanding the compressed archive into a directory:
  48.   7. Once the resource is correctly loaded, the TCompress TargetPath
  49.      and MakeDirectories properties are set, then the full archive
  50.      expansion is handled by this line:
  51.         ExpandFilesFromStream(TempStream,nil); { get the lot }
  52.  
  53.   8. Build this program, run it and give it a safe temporary path --
  54.      the files should be expanded to there and, if you've checked the
  55.      boxes, the extracted program should be run and/or the readme file
  56.      viewed with notepad.
  57. *)
  58. interface
  59.  
  60. uses
  61.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  62.   Forms, Dialogs, StdCtrls, DoInstal;
  63.  
  64. type
  65.   TForm1 = class(TForm)
  66.     TargetDirectory: TEdit;
  67.     RunProgram: TCheckBox;
  68.     ViewReadMe: TCheckBox;
  69.     Install: TButton;
  70.     Label1: TLabel;
  71.     procedure FormCreate(Sender: TObject);
  72.     procedure InstallClick(Sender: TObject);
  73.     procedure TargetDirectoryExit(Sender: TObject);
  74.   private
  75.     { Private declarations }
  76.   public
  77.     { Public declarations }
  78.   end;
  79.  
  80. var
  81.   Form1: TForm1;
  82.  
  83. implementation
  84.  
  85. {$R *.DFM}
  86. {$R COMP_RES.RES}
  87.  
  88.  
  89. const PROG_NAME =   'notepad.exe';
  90.       README_NAME = 'readme.txt';
  91.  
  92. procedure TForm1.FormCreate(Sender: TObject);
  93. begin
  94.      TargetDirectory.text := ExtractFilePath(paramstr(0));
  95. end;
  96.  
  97. procedure TForm1.InstallClick(Sender: TObject);
  98. var ReadMeFile, ExeFile: String;
  99. begin
  100.      ExeFile := '';
  101.      ReadMeFile := '';
  102.      if RunProgram.checked then
  103.         ExeFile := PROG_NAME;
  104.      if ViewReadMe.checked then
  105.         ReadMeFile := README_NAME;
  106.      DoInstall(TargetDirectory.text,ExeFile, ReadMeFile);
  107.      ShowMessage('Installation is complete...');
  108.      close;
  109. end;
  110.  
  111. procedure TForm1.TargetDirectoryExit(Sender: TObject);
  112. var path: string;
  113. begin
  114.      path :=TargetDirectory.text;
  115.      if path<>'' then
  116.         if copy(path,Length(path),1)<>'\' then
  117.            TargetDirectory.text := path+'\';
  118. end;
  119.  
  120. end.
  121.  
  122.